<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<script type="text/javascript">
	var setting = {
		data: {
			simpleData: {
				enable: true
			}
		},
		callback:{
			onClick:function(event, treeId, treeNode, clickFlag) {
				$("#tempChannelId").val(treeNode.id);
				articleTable.fnDraw();
			}
		}
	};
	
	var zNodes = ${treeJson};
	
	$(document).ready(function(){
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		
		articleTable = $("#articleTable").dataTable({
			bAutoWidth: true,
			bFilter: false,
			bLengthChange: false,
			bPaginate: true,
	        bServerSide: true,
	        bSort: false,
	        iDisplayLength: 2,
	        sAjaxSource: "${basePath }/article/table", 
	        sServerMethod: "POST",  
	        fnServerParams: function(aoData) {
                aoData.push(
                    {name: "cid", value: $("#tempChannelId").val()}
                );
            },
	        fnDrawCallback: function(oSettings) {  
	        	$("#datatable td a").css("margin-left", "12px");  
	        },  
			aoColumns: [  
				{"sClass": "center", "mRender": function(data, type, full) {
					return  '<label>'+
							'	<input type="checkbox" class="ace" value='+data+'/>'+
							'	<span class="lbl"></span>'+
							'</label>';
				}},
				{"mDataProp": "id"},
			    {"mDataProp": "title"},
			    {"mDataProp": "click"},
			    {"mDataProp": "publish_time"},
			    {"mRender": function(data, type, full) {
					return '<a href="javascript:;" >编辑</a>&nbsp;<a href="javascript:;" >删除</a>&nbsp;<a href="javascript:;" >发布</a>';
				}}
			],
			aoColumnDefs: [{
				sDefaultContent: '',
				aTargets: [ '_all' ]
			}],
			oLanguage: {
				oAria: {
					sSortAscending: ": activate to sort column ascending",
					sSortDescending: ": activate to sort column descending"
				},
				oPaginate: {
					sFirst: "首页",
					sLast: "末页",
					sNext: "下一页",
					sPrevious: "上一页"
				},
				sEmptyTable: "暂无数据",
				sInfo: "显示 _START_ 到 _END_ 条&nbsp;&nbsp;共 _TOTAL_ 条",
				sInfoEmpty: "显示 0 到 0 条&nbsp;&nbsp;共0 条",
				sInfoFiltered: "(筛选自 _MAX_ 条数据)",
				sInfoPostFix: "",
				sInfoThousands: ",",
				sLengthMenu: "每页显示 _MENU_ 条记录",
				sLoadingRecords: "Loading...",
				sProcessing: "正在加载数据..",
				sSearch: "搜索:",
				sUrl: "",
				sZeroRecords: "没有检索到数据"
			}
		})
		
	});
	
	function toAddArticle() {
		$.ajaxDialog("新增文章", "${basePath}/article/toAdd", {
			"save" :{
				"label" : "<i class='icon-ok'></i> 保存",
				"className" : "btn-sm btn-success",
				"callback": function() {
					alert("保存");
				}
			},
			"cancel" :{
				"label" : " 取消",
				"className" : "btn-sm",
				"callback": function() {
					alert("取消");
				}
			}
		}, "large");
	}
</script>
<div class="breadcrumbs" id="breadcrumbs">
	<script type="text/javascript">
		try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
	</script>
	<ul class="breadcrumb">
		<li>
			<i class="icon-home home-icon"></i>
			<a href="${basePath }/">首页</a>
		</li>

		<li class="active">文章管理</li>
	</ul><!-- .breadcrumb -->

</div>

<div class="page-content">
	<div class="page-header">
		<h1>
			文章管理
			<small>
				<i class="icon-double-angle-right"></i>
				频道的新增、修改、删除、查看、发布
			</small>
		</h1>
	</div><!-- /.page-header -->

	<div class="row">
		<div class="col-xs-12">
			<!-- PAGE CONTENT BEGINS -->

			<div class="row">
				<div class="col-sm-3">
					<div class="widget-box">
						<div class="widget-header header-color-blue2">
							<h4 class="lighter smaller">频道树</h4>
						</div>

						<div class="widget-body">
							<div class="widget-main padding-8">
								<!-- <div id="tree1" class="tree"></div> -->
								<input type="hidden" id="tempChannelId" value="0">
								<ul id="treeDemo" class="ztree"></ul>
							</div>
						</div>
					</div>
				</div>

				<div class="col-sm-9">
					<div class="widget-box">
						<div class="widget-header header-color-green2">
							<h4 id="channelDivTitle" class="lighter smaller">文章列表</h4>
						</div>

						<div class="widget-body">
							<div id="articleDiv" class="widget-main padding-8">
								<div class="table-responsive">
									<button class="btn btn-primary" onclick="toAddArticle()">新增</button>
									<table id="articleTable" class="table table-striped table-bordered table-hover">
										<thead>
											<tr>
												<th class="center">
													<label>
														<input type="checkbox" class="ace" />
														<span class="lbl"></span>
													</label>
												</th>
												<th>ID</th>
												<th>标题</th>
												<th class="hidden-480">点击数</th>
												<th>
													<i class="icon-time bigger-110 hidden-480"></i>
													发布时间
												</th>
												<th class="hidden-480">操作</th>
											</tr>
										</thead>

										<tbody>
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>

			<!-- PAGE CONTENT ENDS -->
		</div><!-- /.col -->
	</div><!-- /.row -->
</div><!-- /.page-content -->
